<%@ page language="java" import="com.newcrm.config.*,com.newcrm.util.Util,java.net.URLEncoder,java.util.List,java.util.Map,java.util.Date,com.newcrm.bean.*" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%
	User user = (User) session.getAttribute("user");
  Map<Integer, CompanyInfo> companys = (Map<Integer, CompanyInfo>) application.getAttribute(Const.APPLICATION_COMPANYS);
  CompanyInfo companyInfo = companys.get(Integer.valueOf(user.companyId));
  List<Map<String, Object>> customerCategorys = companyInfo.customerCategorys;
  List<User> users = companyInfo.users;
  List<Group> allGroups = companyInfo.getAllGroups();

  int authUserNum = companyInfo.qisoukeActivationCode.userNum;
  String authUsers = companyInfo.qisoukeActivationCode.authUsers;
  String qisoukeCode = companyInfo.qisoukeActivationCode.sn;
  String allowGroupIds = companyInfo.allowPublicGroupList;

  // OEM注册码相关信息
  String activeCode = (String) request.getAttribute("activeCode");
  String checkCode = (String) request.getAttribute("checkCode");
  String companyId2 = (String) request.getAttribute("companyId2");
  String expiredDate = (String) request.getAttribute("expiredDate");
  String licenceNum = (String) request.getAttribute("licenceNum");

  // 部门公海开关设置
  boolean isCloseGroupPublicData = companyInfo.isCloseGroupPublicData();

  // 公海客户只读设置
  boolean isPublicReadOnly = companyInfo.isPublicReadOnly();

  String maxNotContactDay = (String) request.getAttribute("maxNotContactDay");
  if (maxNotContactDay == null || "0".equals(maxNotContactDay)) {
    maxNotContactDay = "";
  }
  String categoryIds = (String) request.getAttribute("categoryIds");
  if (categoryIds == null) {
    categoryIds = "";
  }

  String indexStatus = (String) request.getAttribute("indexStatus");
  // 获取产品信息
  ProductInfo productInfo = Config.getInstance().productInfo;
  String productName = productInfo.productName;
  String productId = productInfo.productId;
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
  <title>系统设置</title>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
  <meta name="renderer" content="webkit"/>
  <meta http-equiv="X-UA-Compatible" content="IE=Edge">
  <link rel="shortcut icon" href="<%=request.getContextPath()%>/images/qikebao.ico" />
  <link rel="stylesheet" href="<%=request.getContextPath()%>/css/all.css?ver=<%=Const.VERSION%>">
  <link rel="stylesheet" href="<%=request.getContextPath()%>/css/font-awesome/css/font-awesome.min.css">
  <link rel="stylesheet" href="<%=request.getContextPath()%>/css/datepicker.css" />
  <link rel="stylesheet" href="<%=request.getContextPath()%>/css/bootstrap-datetimepicker.min.css" />
  <link rel="stylesheet" href="<%=request.getContextPath()%>/css/magnific-popup.css">
  <link rel="stylesheet" href="<%=request.getContextPath()%>/css/jplayer.blue.monday.min.css">
  <script type="text/javascript" src="<%=request.getContextPath()%>/script/jquery-1.11.1.min.js"></script>
  <script type="text/javascript" src="<%=request.getContextPath()%>/script/bootstrap.min.js"></script>
  <script type="text/javascript" src="<%=request.getContextPath()%>/script/jquery-ui.min.js"></script>
  <script type="text/javascript" src="<%=request.getContextPath()%>/script/jquery.bootstrap-growl.min.js"></script>
  <script type="text/javascript" src="<%=request.getContextPath()%>/script/moment.min.js"></script>
  <script type="text/javascript" src="<%=request.getContextPath()%>/script/bootstrap-datepicker.js"></script>
  <script type="text/javascript" src="<%=request.getContextPath()%>/script/bootstrap-datetimepicker.min.js"></script>
  <script type="text/javascript" src="<%=request.getContextPath()%>/script/daterangepicker.js"></script>
  <script type="text/javascript" src="<%=request.getContextPath()%>/script/jquery.magnific-popup.min.js"></script>
  <script type="text/javascript" src="<%=request.getContextPath()%>/script/jquery.cookie.js"></script>
  <script type="text/javascript" src="<%=request.getContextPath()%>/script/popbox.js"></script>
  <script type="text/javascript" src="<%=request.getContextPath()%>/script/pageNavi.js?ver=<%=Const.VERSION%>"></script>
  <script type="text/javascript" src="<%=request.getContextPath()%>/script/common.js?ver=<%=Const.VERSION%>"></script>
  <script type="text/javascript" src="<%=request.getContextPath()%>/script/systemsetting.js?ver=<%=Const.VERSION%>"></script>
  <script charset="utf-8" src="http://wpa.b.qq.com/cgi/wpa.php"></script>
  <script>
    var qisoukeUserNum = <%=authUserNum%>;
    $(function() {
      BizQQWPA.add({aty: '0', a: '0', type: '1', nameAccount: 4000187688, parent: 'BizQQWPA'});
<%if (maxNotContactDay.length() > 0) {%>
      $("#setting_isValid").prop('checked', true);
      $("#setting_maxNotContactDay").val("<%=maxNotContactDay%>");
<%if ("*".equals(categoryIds)) {%>
      $("#category_all").attr("v", "1").find("i").addClass("fa-check-square-o").removeClass("fa-square-o");
<%} else {
    for (String id:categoryIds.split(",")) { %>
      $("#category_<%=id%>").attr("v", "1").find("i").addClass("fa-check-square-o").removeClass("fa-square-o");
<%  }
  }
}
 if ("1".equals(indexStatus)) {%>
  $("#rebuild_index_container").hide();
  $("#no_index_container").show();
<% } else {%>
  $("#rebuild_index_container").show();
  $("#no_index_container").hide();
<% }
  if (authUsers != null && authUsers.trim().length() > 0) {
    for (String uid:authUsers.split(",")) {
%>
    $("#qisouke_<%=uid%>").attr("v", "1").find("i").addClass("fa-check-square-o").removeClass("fa-square-o");
<%
    }
  }
  if ("*".equals(allowGroupIds) || allowGroupIds == null) {%>
      $("#allow_all").attr("v", "1").find("i").addClass("fa-check-square-o").removeClass("fa-square-o");
<%} else {
    for (String group:allowGroupIds.split(",")) { %>
      $("#allow_<%=group%>").attr("v", "1").find("i").addClass("fa-check-square-o").removeClass("fa-square-o");
<%  }
  }%>

<% if (qisoukeCode != null && qisoukeCode.trim().length() > 0) { %>
  $("#qisouke-step3").show();
<% } else {%>
  $("#qisouke-step1").show();
<% }%>

<% if (isPublicReadOnly) {%>
   $("#set_publicReadOnly").attr("v", "1").find("i").addClass("fa-check-square-o").removeClass("fa-square-o");
<% }%>

<% if (isCloseGroupPublicData) {%>
   $("#close_groupData").attr("v", "1").find("i").addClass("fa-check-square-o").removeClass("fa-square-o");
<% }%>
    });
  </script>
</head>
<body class="edit_identity">
  <jsp:include page="topNavi.jsp" flush="true"/>

  <div class="main-page">
    <div class="profile-header">
      <div><img src="<%=request.getContextPath()%>/images/setting.png"></div>
      <div class="detail">
        <h1>系统设置</h1>
        <p>定制自己的<%=productName%>，更好的管理客户</p>
      </div>
    </div>
    <div class="clearfix"></div>
    <div class="profile-info-tabs">
      <ul class="nav-tabs" id="tabs">
        <li class="active"><a href="#navi-1">未联系客户设置</a></li>
        <li><a href="#navi-2">搜索索引设置</a></li>
        <!--
        <li><a href="#navi-3">企搜客账号设置</a></li>
        -->
        <li><a href="#navi-4">公海数据保护设置</a></li>
        <% if ("1".equals(productInfo.activeCodeFlag)) {%>
        <li><a href="#navi-5">注册码激活设置</a></li>
        <% } %>
      </ul>
      <div class="nav-detail">
        <div id="navi-1" class="tab-container body setting-panel">
          <h1>未联系客户设置</h1>
          <p class="tips"># 特别提示：设置后，每天晚上凌晨2点时，系统会自动将如下的客户信息划归到公海数据中，<font color="red">并且该过程不可逆。</font></p>
          <ul class="items">
            <li>1. 已联系过，但联系时间间隔超过指定天数</li>
            <li>2. 从未联系过，但创建时间超过指定天数</li>
          </ul>
          <table class="setting">
            <tr><th width="100"><label>开启服务</label></th><td><input type="checkbox" style="margin:10px;" name="setting_isValid" id="setting_isValid" value="1" > <label for="setting_isValid">开启服务</label></td></tr>
            <tr><th><label for="voip_pwd">未联系天数</label></th><td><div style="margin-left:10px;"><input type="text" class="normal" name="setting_maxNotContactDay" id="setting_maxNotContactDay" value="" ></div></td></tr>
            <tr><th><label for="voip_pwd">客户分类</label></th>
            <td>
              <div style="padding-top:5px;width:80%;">
                <div class="clearfix"><span id="category_all" class="checkbox-button"><i class="fa fa-fw fa-square-o"></i> 所有分类</span></div>
                <div class="clearfix" id="categorylist">
                    <span id="category_0" categoryid="0" class="checkbox-button"><i class="fa fa-fw fa-square-o"></i> 无分类</span>
                <%if (customerCategorys != null) {
                    for (Map<String, Object> category:customerCategorys) { %>
                    <span id="category_<%=category.get("CategoryId")%>" categoryid="<%=category.get("CategoryId")%>" class="checkbox-button"><i class="fa fa-fw fa-square-o"></i> <%=Util.HTMLEncode((String)category.get("CategoryName"))%></span>
               <%}
                }%></div>
              </div>
            </td></tr>
            <tr><th></th><td><div style="margin-left:10px;"><a id="setting_link" class="button blue" href="#"><i class="fa fa-check"></i> 修 改 </a> <span class="tips" id="setting_tips"></span></div></td></tr>
          </table>
        </div>
        <div id="navi-2" class="tab-container body setting-panel">
          <h1>搜索索引设置</h1>
          <p class="top10">为了提高<%=productName%>顶部快速查找的检索速度，我们使用了索引管理。</p>
          <p class="top10">如果您觉得你的检索的数据有不一致，或者其他的异常，可以点击下面的按钮，重新创建索引。</p>
          <p class="top10">当客户信息比较多的时候，可能索引会消耗比较长的时间，此时会影响其他的人的搜索操作。</p>
          <p class="top10">推荐在下班或者晚上进行该操作。</p>
          <div class="top10" id="rebuild_index_container">
            <a href="#" id="rebuild_index_link" class="button green"><i class="fa fa-cogs"></i> <span id="rebuild_index_text">全部重新索引</span></a>
            <div class="progressbar-container"><div id="progressbar"></div></div>
          </div>
          <div class="top10" id="no_index_container">
            <a href="#" class="button grey"><i class="fa fa-cogs"></i> 后台正在索引中，请稍后再试</a>
          </div>
        </div>
        <div id="navi-3" class="tab-container body setting-panel">
          <h1>企搜客系统设置</h1>
          <p class="tips"># 如果您已经购买了企搜客，请在此激活注册码，并指定使用的员工。</p>
          <p class="tips"># 如果您尚未购买企搜客，或者想要具体了解相关的功能，可以联系客服。<font color="red">客服热线：400-018-7688 / 010-82433070 客服QQ：4000187688 </font> <span id="BizQQWPA"></span></p>
          <div id="qisouke-step1" class="hide">
            <h2>第一步，激活注册码</h2>
            <table class="setting">
              <tr>
                <th>
                  <label for="qisouke_activeCode">激活注册码</label>
                </th>
                <td>
                  <div style="margin-left:10px;"><input type="text" class="normal" name="qisouke_activeCode" id="qisouke_activeCode" value=""></div>
                </td>
              </tr>
              <tr><th></th><td><div style="margin-left:10px;"><a id="qisouke_active" class="button blue" href="#"><i class="fa fa-check"></i> 激活 </a> <span class="tips" id="qisouke_active_tips"></span></div></td></tr>
            </table>
          </div>
          <div id="qisouke-step2" class="hide">
            <h2>第二步，设置授权使用的员工，员工许可数为： <b id="qisouke_user_num"></b></h2>
            <table class="setting">
              <tr><th><label>授权员工</label></th>
              <td>
                <div class="top10">
                  <div id="userlist">
                    <div class="clearfix">
                      <span id="0">未分配部门</span>
                    <%for (User u:users) {
                        if (u.groupId == 0) {%>
                      <div><span id="qisouke_<%=u.userId%>" userId="<%=u.userId%>" class="checkbox-button"><i class="fa fa-fw fa-square-o"></i> <%=Util.HTMLEncode(u.name)%></span></div>
                    <%  }
                      }%>
                    </div>
                    <%
                      if (allGroups != null) {
                        for (Group group:allGroups) { %>
                    <div class="clearfix" id="group_<%=group.getId()%>">
                      <span id="<%=group.getId()%>"><%=Util.HTMLEncode(group.getName())%></span>
                    <%
                    	    boolean hasUser = false;
                    	    for (User u:users) {
                            if (u.groupId == group.getId()) {
                              hasUser = true;
                              %>
                      <div><span id="qisouke_<%=u.userId%>" userId="<%=u.userId%>" class="checkbox-button"><i class="fa fa-fw fa-square-o"></i> <%=Util.HTMLEncode(u.name)%></span></div>
                    <%
                    	      }
                          }
                    %>
                    </div>
                    <%    if (!hasUser) { %>
                      <script>$("#group_<%=group.getId()%>").remove();</script>
                    <%    }
                        }
                      }
                    %>
                  </div>
                </div>
              </td>
              </tr>
              <tr><th></th><td><div style="margin-left:10px;"><a id="qisouke_user" class="button blue" href="#"><i class="fa fa-check"></i> 设置授权员工 </a> <span class="tips" id="qisouke_user_tips"></span></div></td></tr>
            </table>
          </div>

          <div id="qisouke-step3" class="hide">
            <h2>您已经开通企搜客服务，授权用户数量为 <b id="qisouke_user_num"><%=authUserNum%></b></h2>
            <div>授权员工列表如下：</div>
            <div class="top10 qisouke-users">
<%
          if (authUsers != null && authUsers.trim().length() > 0) {
            for (String u : authUsers.split(",")) {
              String userName = companyInfo.getUserName(u); %>
              <span><i class="fa fa-user"></i> <%=Util.HTMLEncode(userName)%></span>
<%            }
          }
%>
            </div>
            <div class="top10">
              <a id="qisouke_user_reset" class="button blue" href="#"><i class="fa fa-check"></i> 重新设置授权员工 </a>
              <a id="qisouke_active_reset" class="button red" href="#"><i class="fa fa-check"></i> 更换激活码 </a>
            </div>
          </div>
        </div>
        <div id="navi-4" class="tab-container body setting-panel">
          <h1>公海客户只读设置</h1>
          <p class="tips"># 为了明确权限，公海客户<font color="red">默认为只读状态</font>，员工只有将公海的数据划入自己名下，才能对公海客户进行修改，并添加备注。</p>
          <p class="tips"># 操作说明：<font color="red">勾选表明设置公海客户为只读状态，不可直接修改；取消勾选表明公海客户可以正常修改。默认为勾选。</font></p>
          <div class="clearfix"><span id="set_publicReadOnly" class="checkbox-button"><i class="fa fa-fw fa-square-o"></i> 公海客户为只读状态</span>
          </div>

          <h1>部门公海关闭设置</h1>
          <p class="tips"># 部门公海数据，<font color="red">默认开启状态</font>，如果您需要关闭部门公海选项，仅使用公司公海，可以在此进行勾选。</p>
          <p class="tips"># 操作说明：在关闭部门公海之前，<font color="red">请务必先将部门公海内的客户数据转移出来，否则关闭后将无法访问这些客户数据</font></p>
          <div class="clearfix"><span id="close_groupData" class="checkbox-button"><i class="fa fa-fw fa-square-o"></i> 关闭部门公海</span>
          </div>

          <h1>公海数据保护设置</h1>
          <p class="tips"># 公司所属的公海数据，<font color="red">默认是对公司内所有部门开放的</font>，如果您想具体设置公海数据保护，可以对相关部门进行勾选。</p>
          <p class="tips"># 操作说明：如果允许全体部门访问公司所属公海数据，请勾选【所有部门】。
          <p class="tips"># 操作说明：如果有不允许访问的部门，请取消选择【所有部门】的选择，并在部门列表中取消选择该部门；同时，在部门列表中勾选允许访问的部门。</p>
          <table class="setting">
            <tr><th><label for="allowGroupList">允许访问公司所属公海数据的部门</label></th>
            <td>
              <div style="padding-top:5px;width:80%;">
                <div class="clearfix"><span id="allow_all" class="checkbox-button"><i class="fa fa-fw fa-square-o"></i> 所有部门</span></div>
                <div class="clearfix" id="allowGroupList">
                  <%for (Group group:allGroups) {%>
                  <span id="allow_<%=group.getId()%>" groupId="<%=group.getId()%>" class="checkbox-button"><i class="fa fa-fw fa-square-o"></i> <%=Util.HTMLEncode(group.getName())%></span>
                  <%}%>
                </div>
              </div>
            </td>
            </tr>
            <tr><th></th><td><a id="setting_allow" class="button blue" href="#"><i class="fa fa-check"></i> 修 改 </a> <span class="tips" id="setting_tips"></span></td></tr>
          </table>
        </div>

        <div id="navi-5" class="tab-container body setting-panel">
          <h1>注册码激活设置</h1>
          <p class="tips"># 如果注册码失效办理完续费，或者新增用户许可数，可以在此重新激活注册码。</p>
          <table class="setting">
            <tr>
              <th>
                <label for="licenceNum">用户许可数</label>
              </th>
              <td>
                <div style="margin-left:10px;"><input type="text" class="normal" name="licenceNum" id="licenceNum" readonly value="<%=licenceNum%>"></input></div>
              </td>
            </tr>
            <tr>
              <th>
                <label for="expiredDate">到期日期</label>
              </th>
              <td>
                <div style="margin-left:10px;"><input type="text" class="normal" name="expiredDate" id="expiredDate" readonly value="<%=expiredDate%>"></input>
                <input type="hidden" class="normal" name="companyId2" id="companyId2" readonly value="<%=companyId2%>"></input>
                <input type="hidden" class="normal" name="activeCode" id="activeCode" readonly value="<%=activeCode%>"></input>
                </div>
              </td>
            </tr>
            <tr><th></th><td><div style="margin-left:10px;"><a id="oem_active" class="button blue" href="#"><i class="fa fa-check"></i> 激活 </a> <span class="tips" id="oem_active_tips"></span></div></td></tr>
          </table>
      </div>
    </div>
  </div>
</body>
</html>